import React from 'react';
import StoreMallDirectoryOutlined from '@material-ui/icons/StoreMallDirectoryOutlined';
import { NavView, get_mod, loc, NavListSub } from 'sui';
import { LatheView, ForgeView, BlankView } from './base/view';
import { SetView } from './setting';
import { get_access } from 'cache';

const model = (cfg) => {
    const fix = [
        {uid: "outhouse.lathe", view: LatheView, value: loc("l_894")},
        {uid: "outhouse.forge", view: ForgeView, value: loc("l_893")},
        {uid: "outhouse.blank", view: BlankView, value: loc("l_150")},
        {uid: "outhouse.setting", view: SetView, value: loc("l_191")},
    ];

    let ret = get_mod(cfg, fix, "outhouse");
    let acc = get_access();

    if (acc && ret) {
        ret = ret.filter(d => acc.has(d.uid));
    }

    return ret;
};

const Outhouse = ({ mod, sideopen, cfg }) => <NavView cfg={cfg} model={model(cfg)} mod={mod} sideopen={sideopen} name="outhouse"/>;

const NavOuthouse = (props) => <NavListSub icon={<StoreMallDirectoryOutlined/>} sub={model(props.cfg)} {...props} scut={15}/>;

export {NavOuthouse, Outhouse};
